import Vue from 'vue'
import Vuex from 'vuex'

import {
  sysRoleColumnQuery,
  sysRoleColumnDelete,
  sysRoleColumnAdd,
  sysRoleColumnUpdate,
  sysRoleColumnOpenApiQuery,
  sysRoleColumnGetRoleColumn,
  sysRoleColumnGetAll,
  sysRoleColumnClearAll,
} from '@/api/module/sysRoleColumn'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  async querySysRoleColumn({ commit }, listQuery) {
    let res = await sysRoleColumnQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async querySysRoleColumnGetRoleColumn({ commit }, roleId) {
    let res = await sysRoleColumnGetRoleColumn(roleId)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async querySysRoleColumnGetAll({ commit }, userId) {
    let res = await sysRoleColumnGetAll(userId)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async deleteSysRoleColumn({ commit }, row) {
    let res = await sysRoleColumnDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addSysRoleColumn({ commit }, data) {
    let res = await sysRoleColumnAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateSysRoleColumn({ commit }, data) {
    let res = await sysRoleColumnUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryOpenApiSysRoleColumn({ commit }, listQuery) {
    let res = await sysRoleColumnOpenApiQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async clearAllSysRoleColumn({ commit }, data) {
    let res = await sysRoleColumnClearAll(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
